<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: header('新增学生')"/>
</head>
<body>
<div class="form-content">
    <form id="form-student-add" class="form-horizontal">
        <input name="profId" type="hidden" id="treeId"/>
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>学生名称：</label>
                    <div class="col-sm-8">
                        <input name="stuName" autocomplete="off" placeholder="请输入学生名称" class="form-control" type="text"
                               maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>归属班级：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="profName" onclick="selectProfessionTree()" id="treeName" type="text"
                                   placeholder="请选择归属班级" class="form-control" required>
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>学号：</label>
                    <div class="col-sm-8">
                        <input name="stuNum" autocomplete="off" placeholder="请输入学号" class="form-control"
                               type="text" maxlength="11" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>身份证号码：</label>
                    <div class="col-sm-8">
                        <input name="idCard" autocomplete="off" class="form-control" type="text" maxlength="50"
                               placeholder="请输入身份证号码" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>手机号码：</label>
                    <div class="col-sm-8">
                        <input name="phoneNum" autocomplete="off" placeholder="请输入手机号码" class="form-control"
                               type="text" maxlength="11" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>邮箱：</label>
                    <div class="col-sm-8">
                        <input name="email" autocomplete="off" class="form-control email" type="text" maxlength="50"
                               placeholder="请输入邮箱" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">用户性别：</label>
                    <div class="col-sm-8">
                        <div class="input-group" style="width: 100%">
                            <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>登录密码：</label>
                    <div class="col-sm-8">
                        <input name="password" placeholder="请输入登录密码" autocomplete="off" class="form-control"
                               type="password" th:value="${@config.getKey('sys.user.initPassword')}" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">

            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">用户状态：</label>
                    <div class="col-sm-8">
                        <div class="onoffswitch">
                            <input type="checkbox" th:checked="true" class="onoffswitch-checkbox" id="status">
                            <label class="onoffswitch-label" for="status">
                                <span class="onoffswitch-inner"></span>
                                <span class="onoffswitch-switch"></span>
                            </label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">其他信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">备注：</label>
                    <div class="col-xs-10">
                        <textarea name="remark" autocomplete="off" maxlength="500" class="form-control"
                                  rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "maintenance/student";

    $("#form-user-add").validate({
        onkeyup: false,
        rules: {
            /*  stuName: {
                  minlength: 2,
                  maxlength: 20,
              },
              stuNum: {
                  minlength: 2,
                  maxlength: 20,
                  number: true
              },
              idCard: {
                  minlength: 18,
                  maxlength: 18,
                  number: true
              },
              phoneNum: {
                  isPhone: 11,
                  number: true
              },
              loginName: {
                  minlength: 2,
                  maxlength: 20,
              },
              password: {
                  minlength: 5,
                  maxlength: 20
              },
              email: {
                  email: true,
              },*/
        },
        messages: {},
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-student-add").serializeArray();
            var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
            var postIds = $.form.selectSelects("post");
            data.push({"name": "status", "value": status});
            data.push({"name": "profId", "value": postIds});
            $.operate.saveTab(prefix + "/add", data);
        }
    }

    /*学生管理-新增-选择班级树*/
    function selectProfessionTree() {
        var treeId = $("#treeId").val();
        var profId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + profId;
        var options = {
            title: '选择部门',
            width: "380",
            url: ctx + "maintenance/profession/selectProfessionTree/" + profId,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>
